package spring.board;

import java.awt.Frame;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;
import java.io.File;
import java.lang.reflect.Array;
import java.net.URL;
import javax.imageio.ImageIO;


/* DB에 insert, update 시 사용 */
public class imageFile extends Frame{	
	public static Object[] imageRead(){
		try{
			BufferedImage img;
			img = ImageIO.read(new URL("http://blogpfthumb.phinf.naver.net/data20/2006/10/18/156/024_noname-dbuser.jpg"));
			//img = ImageIO.read(new File("123.jpg"));//image read
			Object[] ob = new Object[2];
			ob[0] = "asd";
			ob[1] = img;
			return ob;
			
		}catch(Exception e){
			e.printStackTrace();
		}
		
		return null;
		
	}
	public static void imageWrite(Object[] ob){	
		try{			
			String imgName = (String) ob[0];
			BufferedImage bufferedImg = (BufferedImage) ob[1];
			
			BufferedImage bufferedImage = new BufferedImage(bufferedImg.getHeight(),bufferedImg.getWidth(),BufferedImage.TYPE_INT_BGR);//image size
			
			System.out.println("bufferedImg:"+bufferedImg);
			
			ImageObserver imageWrite = null;
			bufferedImage.createGraphics().drawImage(bufferedImg, 0, 0, imageWrite); //image create
			
			//System.out.println("type: "+bufferedImg.toString());
			ImageIO.write(bufferedImage, "jpg", new File("WebContent/images/"+imgName+".jpg"));//imga write
		}catch(Exception e){
			e.printStackTrace();
		}		
	}
	
	public static void main(String args[]){
		imageWrite(imageRead());
	}
}